/*package com.itheima.Interceptor;

import com.itheima.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Slf4j
@Component
public class TokenInterceptor implements HandlerInterceptor {
    //在业务处理器处理请求之前被调用
    //返回值判断是否放行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("preHandle...");
        String path = request.getRequestURI();
        if (path.contains("/login")) {
            log.info("登录请求");
            return true;
        }
        String token = request.getHeader("token");
        if (token == null) {
            log.info("token为空");
            response.setStatus(401);
            return false;
        }else {
            try {
                JwtUtils.parseJWT(token);
                log.info("令牌校验通过");
                return true;
            }
            catch (Exception e) {
                log.info("令牌校验失败");
                response.setStatus(401);
                return false;
            }
        }
    }
    //在业务处理器处理请求执行完成后，生成视图之前执行的动作
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("postHandle...");
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }
    //在DispatcherServlet完全处理完请求后被调用
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("afterCompletion...");
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }
}*/
